package com.explorati.LeetCode242.isAnagram;

/**
 * @ Author : Weijian_Wang
 * @ Date : Created in 23:01 2020/10/27 0027
 * @ Description ：
 */
public class Solution2 {

    public boolean isAnagram(String s, String t) {
        if (s.length() != t.length()) {
            return false;
        }

        int[] count = new int[26];
        for(int i = 0; i < s.length(); i ++) {
            count[s.charAt(i) - 'a'] ++;
        }

       for(int j = 0; j < t.length(); j ++) {
           if(count[t.charAt(j) - 'a'] == 0) {
               return false;
           }
           count[t.charAt(j) - 'a'] --;
       }

        return true;
    }
}
